{% load staticfiles %}
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>Trade Trends</title>

    <!-- Bootstrap -->
    <link href="{% static '' %}default/css/bootstrap.min.css" rel="stylesheet">
    <link href="{% static '' %}default/css/style.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

      <style>
          ul#sku-item li{ float: left;}
      </style>

  </head>
  <body>
  <nav class="navbar navbar-inverse">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">TradeTrends</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
              <ul class="dropdown-menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li role="separator" class="divider"></li>
                <li class="dropdown-header">Nav header</li>
                <li><a href="#">Separated link</a></li>
                <li><a href="#">One more separated link</a></li>
              </ul>
            </li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>
<div class="container theme-showcase" role="main">

      <!-- Main jumbotron for a primary marketing message or call to action -->





    <div class="container text-center col-lg-6">

          <div>
              <img id="thumb2" src="{% static 'images/loading_sm.gif' %}" width="220" alt=""/>
          </div>


          <form action="" class="form-horizontal">
              <span id="test2" class="btn btn-lg btn-success">获取SKU图片</span>
              <input type="text" id="productUrl" name="productUrl" class="form-control"/>
          </form>




      </div>

    <div class="container text-center col-lg-6">

          <div id="dataPanel">
              <img id="thumb" src="{% static 'images/loading_sm.gif' %}" width="220" alt=""/>
          </div>


          <form action="" class="form-horizontal">
              <span id="test" class="btn btn-lg btn-success">获取产品信息</span>
              <input type="text" id="goodsUrl" name="goodsUrl" class="form-control"/>
              <input type="text" id="company" name="company" class="form-control"/>
              <input type="text" id="goodsTitle" name="goodsTitle" class="form-control"/>
              <input type="text" id="goodsThumb" name="goodsThumb" class="form-control"/>
          </form>




      </div>

    <div class="container col-lg-12">
        <ul id="sku-item">

          </ul>
    </div>






    </div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="{% static '' %}default/js/bootstrap.min.js"></script>

  <script>
     $("#test").click(function(){
         var url = $('#goodsUrl').val();
         if(url.length<=0){
             alert('请填写商品的URL');
             $('#goodsUrl').focus();
             return false;
         }else{
             $.getJSON("{% url 'getAlibaba' %}",
             //$.getJSON("{% url 'getSupplier' %}",
                     { url: url },
                     function(result){
                         //console.log(result);
              if("title" in result && result['title'].length > 0){
                  $('#company').val(result['company']);
                  $('#goodsTitle').val(result['title']);
                  $('#goodsThumb').val(result['thumb']);
                  $('#thumb').attr('src',result['thumb']);
              }else{
                  alert('获取失败！');
              }
          });
         }
     });

      $("#test2").click(function(){
         var url = $('#productUrl').val();
         if(url.length<=0){
             alert('请填写商品的URL');
             $('#productUrl').focus();
             return false;
         }else{
             //$.getJSON("http://watch.censh.com/api/getSku/",
             $.getJSON("{% url 'getSku' %}",
                     { url: url },
                     function(result){
                         //console.log(result);
              if("thumb" in result && result['thumb'].length > 0){
                  $('#thumb2').attr('src',result['thumb']);

                  var skuPanel = $('#sku-item');

                  skuPanel.html('');

                  $.each(result["skuImg"], function (i, sku) {
                        skuPanel.append('<li><p><img src="'+sku["img"]+'" width=80 /></p><span>' + sku["name"] + '</span></li>');
                    }
                );


              }else{
                  alert('获取失败！');
              }
          });
         }
     });

  </script>



  </body>
</html>